//
//  ZZBaseViewController.m
//  zhengzai-tv
//
//  Created by 孙超 on 16/3/8.
//  Copyright © 2016年 zhengzai.tv. All rights reserved.
//

#import "ZZBaseViewController.h"
#import "RZDataBinding.h"

@interface ZZBaseViewController ()

@property (nonatomic, strong) ZZBaseViewModel *viewModel;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation ZZBaseViewController

@synthesize contentInset = _contentInset;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.extendedLayoutIncludesOpaqueBars = YES;
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    self.navigationController.navigationBar.translucent = NO;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.titleLabel setTextColor:[UIColor whiteColor]];
    self.navigationItem.titleView = self.titleLabel;
    [self bindViewModel];
}

- (instancetype)initWithViewModel:(ZZBaseViewModel *)viewModel
{
    self = [super init];
    if (self != nil) {
        self.viewModel = viewModel;
    }
    return self;
}

- (void)bindViewModel
{
    self.titleLabel.text = self.viewModel.title;
    [self.titleLabel sizeToFit];
    [self.viewModel rz_addTarget:self action:@selector(titleChange:) forKeyPathChange:@"title"];
}

- (void)titleChange:(id)sender
{
    self.titleLabel.text = self.viewModel.title;
    [self.titleLabel sizeToFit];
}

- (BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

@end
